import { ref, computed, reactive } from 'vue'
import { $get, $post } from '~mixins/useRequest'
import { $mc, $ms } from '~mixins/useMsg'
// 用于表格ref的对象名
export let tb = ref(null)

/**
 * 本页面查询所需的参数
 */
export let localParams = reactive({
    keywords: '',
    payState: [],
    deliveryState: null
})

/**
 * 获取数据，各页面基本按这个规则写就行
 * 数据必须返回如下格式，或者修改组件
 *      {
 *          data:{
                list:Array,
                total:number
            }
 *      }
 *  */
export function getList(params) {
    let query = Object.assign({}, localParams, params, {
        payState: localParams.payState.join()
    })
    return $get("/order/list", query);
}
// watch(deliveryState, getList)
// watch(current, getList)
export let unSelected = computed(() => !tb.value || tb.value.selectedRowKeys.length === 0)


export async function updatePayState(id, state) {
    await $mc("确定更新状态？");
    let { success } = await $post("/order/updatestate", { id, state });
    if (success) {
        $ms("状态修改成功!");
        tb.value.refresh();
    }
}

export async function del(orderId) {
    await $mc("删除后将无法恢复，确定删除？");
    let { success } = await $post("/order/del", { orderId });
    if (success) {
        $ms("删除成功!");
        tb.value.refresh();
    }
}

export async function updateMultiState({ key: state }) {
    await $mc("确定更新状态？");
    $ms("批量修改订单付款状态成功!", '嘿嘿，其实没有后台接口，假的');
    tb.value.selectedRowKeys = [];
    // let { success } = await $post("/order/updateMultiState", {
    //     state,
    //     ids: tb.value.selectedRowKeys.join(","),
    // });
    // if (success) {
    //     $ms("批量修改订单付款状态成功!");
    //     tb.value.refresh();
    // }
}